{% extends 'channel/base.html' %}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>channel Apk</title>
</head>
<body>
{% block content %}
    <div>
        <p style="text-align: center; font-weight: 900;font-size: 30px">渠道包下载</p>
    </div>
    <div class="col-lg-12">
        <h4>当前版本:{{ version }}</h4>
    </div>
    <div>
        <table class="table table-bordered" style="padding:0 25px">
            <thead>
            <tr>
                <th>渠道包id</th>
                <th>版本</th>
                <th>渠道号</th>
                <th>下载地址</th>
            </tr>
            </thead>
            <tbody>
            {% for foo in apkInfo %}
                <tr>
                    <td class="apkId">{{ foo.id }}</td>
                    <td class="apkVersion">{{ foo.status }}</td>
                    <td class="apkChannelNum">{{ foo.title }}</td>
                    <td class="apkDownUrl"><a href="{{ foo.actionurl }}">{{ foo.actionurl }}</a></td>
                </tr>
            {% endfor %}
            </tbody>
        </table>

        <div class="sss">
        </div>

    </div>
    <div class="group-bbb">
        <div class="col-lg-12">
            <h4>历史版本</h4>
        </div>
        <div class="col-lg-12">
            <div class="btn-toolbar" role="toolbar">
                <div class="btn-group">
                    <button type="button" class="btn btn-primary" value="4030"
                            onclick="getHistortChannelApk(this.value)">4030
                    </button>
                </div>
                <div class="btn-group">
                    <button type="button" class="btn btn-primary" value="4020"
                            onclick="getHistortChannelApk(this.value)">4020
                    </button>
                </div>
                <div class="btn-group">
                    <button type="button" class="btn btn-primary" value="4010"
                            onclick="getHistortChannelApk(this.value)">4010
                    </button>
                </div>
                <div class="btn-group">
                    <button type="button" class="btn btn-primary" value="4000"
                            onclick="getHistortChannelApk(this.value)">4000
                    </button>
                </div>
                <div class="btn-group">
                    <button type="button" class="btn btn-primary" value="3090"
                            onclick="getHistortChannelApk(this.value)">3090
                    </button>
                </div>
                <div class="btn-group">
                    <button type="button" class="btn btn-primary" value="3080"
                            onclick="getHistortChannelApk(this.value)">3080
                    </button>
                </div>
            </div>
        </div>
    </div>
    <div>
        <table id="ajaxPost" class="table">
            <tr></tr>
            <tbody class="iou">
            </tbody>
        </table>
    </div>
    <div id="errorInfo" class="col-lg-12">

    </div>
    <a href=""></a>
    <script type="application/javascript">
        function getHistortChannelApk(version) {
            //Django认证
            $.ajaxSetup({
                data: {csrfmiddlewaretoken: '{{ csrf_token }}'}
            });
            $.ajax({
                    url: "{% url 'channel:getHistoryVersion' %}",
                    type: 'POST',
                    dataType: 'json',
                    data: {'version': version},
                    success: function (data) {
                        //如果不存在该版本，删除tbody.iou，给出提示
                        if (data.errorinfo) {
                            $('tbody.iou').empty();
                            $('#errorInfo').empty();
                            $('#errorInfo').append("<p class='text-danger'>未找到该版本</p>");
                        } else {
                            $('#errorInfo').empty();
                            $('tbody.iou').empty();
                            for (var i = 0; i < data.dd.length; i++) {
                                $('tbody.iou').append("<tr><td><a href =http://127.0.0.1:8000/" + data.dd[i].downloadrl + ">" + "http://127.0.0.1:8000/" + data.dd[i].downloadrl + "</a></td><tr>");
                            }
                        }
                    },
                    error: function (data) {
                        alert('data不存在')
                    }
                }
            )
        }
    </script>
    <script src="http://libs.baidu.com/jquery/2.1.4/jquery.min.js"></script>
{% endblock content %}
</body>
</html>